package adaper;

import com.lx.idgenerator.segement.leaf.ILeafInfoService;
import com.lx.idgenerator.segement.leaf.LeafInfo;
import redis.client.RedisClientManager;

/**
 * Mysql Leaf适配
 *
 * @author wcy
 */
public class RedisLeafInfoService implements ILeafInfoService {


    private RedisClientManager redisClientManager;

    private Long step;

    public RedisLeafInfoService(RedisClientManager redisClientManager,Long step) {
        this.redisClientManager = redisClientManager;
        this.step = step;
    }



    @Override
    public LeafInfo getLeafInfo(String tag) {

        Long currentId = redisClientManager.getNextId(tag,step);

        LeafInfo leafInfo = new LeafInfo();
        leafInfo.setCurId(currentId);
        leafInfo.setTag(tag);
        leafInfo.setMaxId(currentId + step);
        leafInfo.setUpdateTime(System.currentTimeMillis());

        return leafInfo;
    }
}
